<?php

namespace common\models;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;

/**
 * This is the model class for table "{{%goods_extra}}".
 *
 * @property integer $id
 * @property integer $goods_id
 * @property integer $group_id
 * @property integer $package_id
 * @property integer $sale
 * @property integer $created_at
 * @property integer $updated_at
 *
 * @property Goods     $good
 * @property UserGroup $group
 * @property Package   $package
 */
class GoodsExtra extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%goods_extra}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['goods_id', 'group_id', 'package_id', 'created_at', 'updated_at'], 'integer'],
            ['sale', 'integer', 'min'=>1, 'max'=>100],
            [['goods_id', 'sale', 'group_id'], 'required'],
        ];
    }
    
    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
                ]
            ]
        ];
    }
    
    
    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => '排序',
            'goods_id' => '诊疗项目',
            'group_id' => '人群',
            'package_id' => '会员卡',
            'sale' => '折扣',
            'created_at' => '创建时间',
            'updated_at' => '修改时间',
        ];
    }
    
    public function getGood()
    {
        return $this->hasOne(Goods::className(), ['goods_id' => 'goods_id']);
    }
    
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getGroup()
    {
        return $this->hasOne(UserGroup::className(), ['group_id' => 'group_id']);
    }
    
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getPackage()
    {
        return $this->hasOne(Package::className(), ['package_id' => 'package_id']);
    }
}
